/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.sample.library.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.sample.library.model.AuthorBook;
import com.sample.library.model.AuthorBookModel;
import com.sample.library.model.AuthorBookSoap;
import com.sample.library.service.persistence.AuthorBookPK;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the AuthorBook service. Represents a row in the &quot;ATS_AuthorBook&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.sample.library.model.AuthorBookModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AuthorBookImpl}.
 * </p>
 *
 * @author Nguyen Tuan Anh
 * @see AuthorBookImpl
 * @see com.sample.library.model.AuthorBook
 * @see com.sample.library.model.AuthorBookModel
 * @generated
 */
@JSON(strict = true)
public class AuthorBookModelImpl extends BaseModelImpl<AuthorBook>
	implements AuthorBookModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a author book model instance should use the {@link com.sample.library.model.AuthorBook} interface instead.
	 */
	public static final String TABLE_NAME = "ATS_AuthorBook";
	public static final Object[][] TABLE_COLUMNS = {
			{ "bookId", Types.BIGINT },
			{ "authorId", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table ATS_AuthorBook (bookId LONG not null,authorId VARCHAR(75) not null,primary key (bookId, authorId))";
	public static final String TABLE_SQL_DROP = "drop table ATS_AuthorBook";
	public static final String DATA_SOURCE = "sampleDataSource";
	public static final String SESSION_FACTORY = "sampleSessionFactory";
	public static final String TX_MANAGER = "sampleTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.sample.library.model.AuthorBook"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.sample.library.model.AuthorBook"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = false;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static AuthorBook toModel(AuthorBookSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		AuthorBook model = new AuthorBookImpl();

		model.setBookId(soapModel.getBookId());
		model.setAuthorId(soapModel.getAuthorId());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<AuthorBook> toModels(AuthorBookSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<AuthorBook> models = new ArrayList<AuthorBook>(soapModels.length);

		for (AuthorBookSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.sample.library.model.AuthorBook"));

	public AuthorBookModelImpl() {
	}

	public AuthorBookPK getPrimaryKey() {
		return new AuthorBookPK(_bookId, _authorId);
	}

	public void setPrimaryKey(AuthorBookPK primaryKey) {
		setBookId(primaryKey.bookId);
		setAuthorId(primaryKey.authorId);
	}

	public Serializable getPrimaryKeyObj() {
		return new AuthorBookPK(_bookId, _authorId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey((AuthorBookPK)primaryKeyObj);
	}

	public Class<?> getModelClass() {
		return AuthorBook.class;
	}

	public String getModelClassName() {
		return AuthorBook.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("bookId", getBookId());
		attributes.put("authorId", getAuthorId());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long bookId = (Long)attributes.get("bookId");

		if (bookId != null) {
			setBookId(bookId);
		}

		String authorId = (String)attributes.get("authorId");

		if (authorId != null) {
			setAuthorId(authorId);
		}
	}

	@JSON
	public long getBookId() {
		return _bookId;
	}

	public void setBookId(long bookId) {
		_bookId = bookId;
	}

	@JSON
	public String getAuthorId() {
		if (_authorId == null) {
			return StringPool.BLANK;
		}
		else {
			return _authorId;
		}
	}

	public void setAuthorId(String authorId) {
		_authorId = authorId;
	}

	@Override
	public AuthorBook toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (AuthorBook)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		AuthorBookImpl authorBookImpl = new AuthorBookImpl();

		authorBookImpl.setBookId(getBookId());
		authorBookImpl.setAuthorId(getAuthorId());

		authorBookImpl.resetOriginalValues();

		return authorBookImpl;
	}

	public int compareTo(AuthorBook authorBook) {
		AuthorBookPK primaryKey = authorBook.getPrimaryKey();

		return getPrimaryKey().compareTo(primaryKey);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		AuthorBook authorBook = null;

		try {
			authorBook = (AuthorBook)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		AuthorBookPK primaryKey = authorBook.getPrimaryKey();

		if (getPrimaryKey().equals(primaryKey)) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return getPrimaryKey().hashCode();
	}

	@Override
	public void resetOriginalValues() {
	}

	@Override
	public CacheModel<AuthorBook> toCacheModel() {
		AuthorBookCacheModel authorBookCacheModel = new AuthorBookCacheModel();

		authorBookCacheModel.bookId = getBookId();

		authorBookCacheModel.authorId = getAuthorId();

		String authorId = authorBookCacheModel.authorId;

		if ((authorId != null) && (authorId.length() == 0)) {
			authorBookCacheModel.authorId = null;
		}

		return authorBookCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(5);

		sb.append("{bookId=");
		sb.append(getBookId());
		sb.append(", authorId=");
		sb.append(getAuthorId());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(10);

		sb.append("<model><model-name>");
		sb.append("com.sample.library.model.AuthorBook");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>bookId</column-name><column-value><![CDATA[");
		sb.append(getBookId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>authorId</column-name><column-value><![CDATA[");
		sb.append(getAuthorId());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = AuthorBook.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			AuthorBook.class
		};
	private long _bookId;
	private String _authorId;
	private AuthorBook _escapedModelProxy;
}